package com.eightbears.beboy.base.util;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.eightbears.beboy.entity.ShopListEntity;
import com.eightbears.beboy.R;
import com.socks.library.KLog;

import java.io.File;

import static com.eightbears.beboy.base.util.CommonAPI.TYPE_SHOP_BAR;
import static com.eightbears.beboy.base.util.CommonAPI.TYPE_SHOP_KTV;
import static com.eightbears.beboy.base.util.CommonAPI.TYPE_SHOP_MUZU;
import static com.eightbears.beboy.base.util.CommonAPI.TYPE_SHOP_OTHER;
import static com.eightbears.beboy.base.util.CommonAPI.TYPE_SHOP_SHUILIAO;
import static com.eightbears.beboy.base.util.CommonAPI.TYPE_SHOP_YEZONGHUI;

/**
 * Created by baoga on 2017/7/9.
 */

public class AMapUtil {

    /**
     * 检查app安装
     */
    public static boolean isInstallByRead(String packageName) {
        return new File("/data/data/" + packageName).exists();
    }

    public static BitmapDescriptor getTipByShopTip(ShopListEntity.DataBean.ListBean listBean) {
        int ImageResouse = 0;
        switch (listBean.getType()) {
            case TYPE_SHOP_SHUILIAO:
                ImageResouse = R.drawable.icon_shuiliao;
                break;
            case TYPE_SHOP_KTV:
                ImageResouse = R.drawable.icon_ktv;
                break;
            case TYPE_SHOP_YEZONGHUI:
                ImageResouse = R.drawable.icon_yezonghui;
                break;
            case TYPE_SHOP_BAR:
                ImageResouse = R.drawable.icon_bar;
                break;
            case TYPE_SHOP_MUZU:
                ImageResouse = R.drawable.icon_muzu;
                break;
            case TYPE_SHOP_OTHER:

                ImageResouse = R.drawable.icon_other;
            case "6":
            case "7":
            case "8":
            case "9":
            case "10":
            case "11":
            case "0":
                KLog.e(listBean.getType());
                break;
        }
        return BitmapDescriptorFactory.fromResource(ImageResouse);

    }

    public static void goToNaviAmapActivity(Context context, String sourceApplication, String poiname, String lat, String lon, String dev, String style) {
        StringBuffer stringBuffer = new StringBuffer("androidamap://navi?sourceApplication=")
                .append(sourceApplication);
        if (!TextUtils.isEmpty(poiname)) {
            stringBuffer.append("&poiname=").append(poiname);
        }
        stringBuffer.append("&lat=").append(lat)
                .append("&lon=").append(lon)
                .append("&dev=").append(dev)
                .append("&style=").append(style);
        Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse(stringBuffer.toString()));
        intent.setPackage("com.autonavi.minimap");
        context.startActivity(intent);
    }

    public static void goToNaviBaidumapActivity(Context context, String lat, String lng, String lat1, String lng1, String city) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setData(Uri
                .parse("baidumap://map/direction?destination=name+" + city + "|latlng:" + lat1 + "," + lng1 + "&mode=driving&index=0&target=1"));
        context.startActivity(intent);//动用启动
    }

    public static boolean IsEmptyOrNullString(String s) {
        return (s == null) || (s.trim().length() == 0);
    }
}
